import Vue from 'vue'//一级路由
import VueRouter from 'vue-router'
import Home from '@/views/Home.vue'
import Login from "@/views/login.vue"
import kj from "@/views/kj.vue"
import ChangeCity from "@/views/ChangeCity.vue"
import Shoplist from "@/views/shoplist.vue"
import mapfloor from "@/views/mapfloor.vue"
import detail from "@/views/detail.vue"
import fabu from "@/views/fabu.vue"
import Video from "@/views/video.vue"
Vue.use(VueRouter)
//缺省的页面
import err from "./err"
import MainPage from './mianPage'
const routes = [
  ...err,
  {
    path: '/',
    name: 'Home',
    component: Home,
    children: [
//遍历MainPage
      ...MainPage]
  },
  {
    //都别忘了/
    path: "/login",
    name: "Login",
    component: Login,
   

  },{
    //城市列表属于一级路由
    path:"/changecity",
    component:ChangeCity
  },{
    //城市列表属于一级路由
    path:"/shoplist/:id",
    component:Shoplist
  },{
    path:"/mapfloor",
    component:mapfloor
  },{
    path:"/detail/:id",
    component:detail
  },{
    path:"/kj",
    component:kj
  },{
    path:"/fabu",
    component:fabu
  },
  {
    path:"/video",
    component:Video 
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


router.beforeEach((to, from, next) => {
  //获取token值
  const token = localStorage.getItem("token")
  //如果token值不正确并且登录页面的路径不对的话，
  //就还在登录页面
  //写token,必须在页面加token,要不然不管啥情况他都不会跳转页面，即使账号密码正确，它也跳不过去
  if (!token && to.path !== "/login" && !to.meta.filter) {
    next("/login")
  } else {
    next()
  }
})



export default router
